package com.bckj.fastboot.core.extra.relational;

import java.util.Collection;
import java.util.function.Consumer;

/**
 * FilterBuilder
 *
 * @author wfc
 * @date 2025/11/11 13:44
 **/
public interface FilterBuilder<T extends FilterBuilder<T>> {

    T getChildren();

    T where(String field, Object value, String opt);

    T eq(String field, Object value);

    default T eq(boolean condition, String field, Object value) {
        return condition ? eq(field, value) : getChildren();
    }

    T ne(String field, Object value);

    default T ne(boolean condition, String field, Object value) {
        return condition ? ne(field, value) : getChildren();
    }

    T gt(String field, Object value);

    default T gt(boolean condition, String field, Object value) {
        return condition ? gt(field, value) : getChildren();
    }

    T ge(String field, Object value);

    default T ge(boolean condition, String field, Object value) {
        return condition ? ge(field, value) : getChildren();
    }

    T lt(String field, Object value);

    default T lt(boolean condition, String field, Object value) {
        return condition ? lt(field, value) : getChildren();
    }

    T le(String field, Object value);

    default T le(boolean condition, String field, Object value) {
        return condition ? le(field, value) : getChildren();
    }

    T like(String field, Object value);

    default T like(boolean condition, String field, Object value) {
        return condition ? like(field, value) : getChildren();
    }

    T likeLeft(String field, Object value);

    default T likeLeft(boolean condition, String field, Object value) {
        return condition ? likeLeft(field, value) : getChildren();
    }

    T likeRight(String field, Object value);

    default T likeRight(boolean condition, String field, Object value) {
        return condition ? likeRight(field, value) : getChildren();
    }

    T between(String field, Object val1, Object val2);

    default T between(boolean condition, String field, Object val1, Object val2) {
        return condition ? between(field, val1, val2) : getChildren();
    }

    T in(String field, Collection<?> coll);

    default T in(boolean condition, String field, Collection<?> coll) {
        return condition ? in(field, coll) : getChildren();
    }

    T notIn(String field, Collection<?> coll);

    default T notIn(boolean condition, String field, Collection<?> coll) {
        return condition ? notIn(field, coll) : getChildren();
    }

    T isNull(String column);

    default T isNull(boolean condition, String column) {
        return condition ? isNull(column) : getChildren();
    }

    T isNotNull(String column);

    default T isNotNull(boolean condition, String column) {
        return condition ? isNotNull(column) : getChildren();
    }

    T and(Consumer<FilterBuilder<?>> consumer);

    T or();
}
